package ParseConfigFileStrategy

import (
	"dbManager/manager/config"
	"dbManager/manager/utils"
	"log"
)

type CustomParseConfigFileStrategy struct {
	Path   string
	Config config.SqliteConfig
	Format string
}

func (customParseConfigFileStrategy CustomParseConfigFileStrategy) Parse() config.Config {
	var err error
	switch customParseConfigFileStrategy.Format {
	case "toml":
		err = utils.TomlDecode(path, &customParseConfigFileStrategy.Config)
	case "json":
		err = utils.JsonDecode(path, &customParseConfigFileStrategy.Config)
	}
	if err != nil {
		log.Println(err)
		return nil
	}
	return &customParseConfigFileStrategy.Config
}
